package com.zxkj.config;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.repository.config.EnableSolrRepositories;

import javax.annotation.Resource;

/**
 * @author Christoph Strobl
 */
@Configuration
@EnableSolrRepositories(basePackages = {"com.zxkj.solr"})
public class SearchContext {
    @Autowired
    private SolrClient solrClient;

    @Bean
    public SolrTemplate solrTemplate() throws Exception {
        return new SolrTemplate(solrClient);
    }

    @Bean
    public SolrClient solrClient(@Value("${spring.data.solr.host}") String solrHost) {
        HttpSolrClient solrClient = new HttpSolrClient(solrHost);
        return solrClient;
    }


    @Autowired
    private SolrClient solrClient2;

    @Bean
    public SolrTemplate solrTemplate2() throws Exception {
        return new SolrTemplate(solrClient2);
    }

    @Bean
    public SolrClient solrClient2(@Value("${spring.data.solr.host2}") String solrHost) {
        HttpSolrClient solrClient = new HttpSolrClient(solrHost);
        return solrClient;
    }
}
